<template>
  <div>
    <el-card style="width:100%">
      <p>上架管理</p>
      <div class="right">
        <div class="searchAreaTop flex">
          <el-form ref="serachForm" :model="searchForm" :inline="true">
            <el-form-item prop="orderNum">
              <el-input v-model="searchForm.orderNum" placeholder="制造商料号"></el-input>
          </el-form-item>
          <el-form-item prop="menuName">
            <el-select v-model="searchForm.value" filterable clearable
                       placeholder="请选择制造商">
              <el-option v-for="item in AllSlist"
                         :key='item.id'
                         :label="item.menuName"
                         :value="item.menuName"></el-option>
            </el-select>
          </el-form-item>
            <el-form-item prop="showValue">
						<el-select v-model="searchForm.showValue" placeholder="请选择是否上架">
							<el-option label="全部" value="-1"></el-option>
							<el-option label="上架" value="1"></el-option>
              <el-option label="未上架" value="0"></el-option>
						</el-select>	
					</el-form-item>
            <el-form-item prop="action">
              <el-button size="medium" type="primary" @click="searchData">搜索</el-button>
            </el-form-item>
            <el-form ref="serachForm" :model="searchForm" :inline="true">
            <el-form-item prop="action">
              <el-button
                type="primary"
                @click="downloadExcelModel"
              >批量修改价格模板下载</el-button>
              <el-button type="primary" @click="uploadExcelSheetVisible=true">批量修改价模板导入</el-button>
            </el-form-item>
          </el-form>
          </el-form>
        </div>
      </div>
      <div class="tableBox">
        <el-table
          ref="multipleTable"
          :data="tableData"
          style="width: 100%"
          height="500"
          stripe
          @selection-change="handleSelectionChange"
        >
          <el-table-column prop="image" label="产品图片" align="center">
            <template slot-scope="scope">
              <img :src="scope.row.image" min-width="70" height="70" />
            </template>
          </el-table-column>
          <el-table-column prop="productCode" label="制造商料号" align="center"></el-table-column>
          <el-table-column prop="askCode" label="AKS料号" align="center"></el-table-column>
          <el-table-column prop="menuName" label="制造商" align="center"></el-table-column>
          <el-table-column prop="locked" label="是否上架" align="center">
            <template slot-scope="scope">
              <el-tag type="success" v-show="scope.row.isShow==1">上架</el-tag>
              <el-tag type="danger" v-show="scope.row.isShow==0">未上架</el-tag>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" fixed="right" width="450">
            <template slot-scope="scope">
              <el-row>
                <el-button-group>
                  <el-button type="primary" size="mini"  @click="detail(scope.row)">查看</el-button>
                  
                  <el-button type="primary" size="mini"   @click="showFoxUpDialog(scope.row)" >内部参考资料</el-button>
               
                  <el-button type="primary" size="mini"   @click="downloadFox(scope.row)" >内部资料预览</el-button>
              
                  <el-button type="primary" size="mini"  @click="updatePrice(scope.row)" >梯价</el-button>

                </el-button-group>
                <p style="padding:1px 0"></p>
                <el-button-group>
                  <el-button type="primary" size="mini"  @click="downloadAml(scope.row)">AML资料预览</el-button>
                  <el-button type="primary" size="mini"  @click="showShopUpDialog(scope.row)">规格书上传</el-button>
                  <el-button type="primary" size="mini"  @click="selectDate(scope.row)">交货期</el-button>
                  <el-button
                    v-if="scope.row.isShow==1"
                    size="mini"
                    type="danger"
                    @click="userapply(scope.row)"
                  >下架申请</el-button>
                  <el-button
                    v-else
                    size="mini"
                    type="success"
                    plain
                    @click="uploadDialog(scope.row)"
                  >上架申请</el-button>
                </el-button-group>
              </el-row>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          style="text-align:center;margin-top:20px"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-sizes="[5, 10, 15, 20]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        ></el-pagination>
      </div>
    </el-card>
    <el-dialog title="价格梯度修改" :visible.sync="dialogProductFormVisible" width="60%">
        <el-form ref="productForm"
               :model="productForm"
               class="infos flex">
        <el-form-item label="梯度1起始数量"
                      prop="description"
                      style="width:30%">
              <el-input v-model="productForm.countstart1" ></el-input>
        </el-form-item>
        <el-form-item label="梯度1结束数量"
                      prop="description"
                      style="width:30%">
              <el-input v-model="productForm.countend1" ></el-input>
        </el-form-item>

         <el-form-item label="梯度1价格"
                      prop="description"
                      style="width:30%">
              <el-input v-model="productForm.price1" ></el-input>
        </el-form-item>

        <el-form-item label="梯度2起始数量"
                      prop="description"
                      style="width:30%">
              <el-input v-model="productForm.countstart2" ></el-input>
        </el-form-item>
         <el-form-item label="梯度2结束数量"
                      prop="description"
                      style="width:30%">
              <el-input v-model="productForm.countend2" ></el-input>
        </el-form-item>

         <el-form-item label="梯度2价格"
                      prop="description"
                      style="width:30%">
              <el-input v-model="productForm.price2" ></el-input>
        </el-form-item>

        <el-form-item label="梯度3起始数量"
                      prop="description"
                      style="width:30%">
              <el-input v-model="productForm.countstart3" ></el-input>
        </el-form-item>
         <el-form-item label="梯度3结束数量"
                      prop="description"
                      style="width:30%">
              <el-input v-model="productForm.countend3" ></el-input>
        </el-form-item>

         <el-form-item label="梯度3价格"
                      prop="description"
                      style="width:30%">
              <el-input v-model="productForm.price3" ></el-input>
        </el-form-item>
         <el-form-item label="大于梯度3结束数量的价格"
                      prop="description"
                      style="width:100%">
              <el-input v-model="productForm.price4" ></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogProductFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="modifyPrice">确 定</el-button>
      </div>
    </el-dialog>
    <el-dialog
      title="提示"
      :visible.sync="uploadExcelSheetVisible"
      width="35%"
    >
      <span>上传excel文件</span>
      <el-upload
        class="upload-demo"
        drag
        :show-file-list="false"
        :multiple="false"
        :before-upload="beforeUploadExcel"
        :http-request="uploadExcel"
        action
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">
          将文件拖到此处，或
          <em>点击上传</em>
        </div>
        <div class="el-upload__tip" slot="tip">{{updateForm.excelUrl}}</div>
      </el-upload>
    </el-dialog>
    <el-dialog
      title="提示"
      :visible.sync="uploadDateSheetVisible"
      width="35%"
    >
      <span>上传文件</span>
      <el-upload
        class="upload-demo"
        drag
        :show-file-list="false"
        :multiple="false"
        :before-upload="beforeUploadPdf"
        :http-request="uploadPdf"
        action
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">
          将文件拖到此处，或
          <em>点击上传</em>
        </div>
        <div class="el-upload__tip" slot="tip">{{updateForm.pdfUrl}}</div>
      </el-upload>
    </el-dialog>
    <!-- fox上传资料 -->
    <el-dialog
      title="提示"
      :visible.sync="uploadFoxDateSheetVisible"
      width="35%"
    >
      <span>上传文件</span>
      <el-upload
        class="upload-demo"
        drag
        :show-file-list="false"
        :multiple="false"
        :before-upload="beforeUploadPdf"
        :http-request="uploadPdf"
        action
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">
          将文件拖到此处，或
          <em>点击上传</em>
        </div>
        <div class="el-upload__tip" slot="tip">{{updateForm.pdfUrl}}</div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button @click="uploadFoxDateSheetVisible = false">取 消</el-button>
        <el-button type="primary" @click="uploadFoxSource">确 定</el-button>
      </div>
    </el-dialog>
    <!-- 商上传资料 -->
    <el-dialog
      title="提示"
      :visible.sync="uploadShopDateSheetVisible"
      width="35%"
    >
      <span>上传文件</span>
      <el-upload
        class="upload-demo"
        drag
        :show-file-list="false"
        :multiple="false"
        :before-upload="beforeUploadPdf"
        :http-request="uploadPdf"
        action
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">
          将文件拖到此处，或
          <em>点击上传</em>
        </div>
        <div class="el-upload__tip" slot="tip">{{updateForm.pdfUrl}}</div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button @click="uploadShopDateSheetVisible = false">取 消</el-button>
        <el-button type="primary" @click="uploadShopSource">确 定</el-button>
      </div>
    </el-dialog>
    <el-dialog
      title="上下架提示"
      :visible.sync="uploadDialogVisible"
      width="30%"
    >
      <span>{{uploadValue}}</span>
      <div slot="footer" class="dialog-footer">
        <el-button @click="uploadDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="updateShelf">确 定</el-button>
      </div>
    </el-dialog>
    
    <el-dialog title="物料详情" :visible.sync="dialogDetail" width="60%">
      <el-form ref="infoForm"
               :model="infoForm"
               label-position="left"
               label-width="120px"
               class="infos flex">
        <h3 style="width:100%;text-align:center;margin-bottom:15px">物料详情</h3>
        
        <el-form-item label-width='170px' label="制造商料号"
                      prop="productCode"
                      style="width:45%">
          <el-input v-model="infoForm.productCode"
                    :disabled="isDisabled"></el-input>
        </el-form-item>
        <el-form-item label-width='170px' label="AKS料号"
                      prop="askCode"
                      style="width:45%">
          <el-input v-model="infoForm.askCode"
                    :disabled="isDisabled"></el-input>
        </el-form-item>
        <!-- 详情界面 TODO 禁止修改 -->
        <el-form-item label-width='170px' label="制造商"
                      prop="menuName"
                      style="width:45%;">
             <el-input v-model="infoForm.menuName"
                    :disabled="isDisabled"></el-input>
        </el-form-item>
        <!--
        <el-form-item label-width='170px' label="对无铅要求的达标情况"
                      prop="standard"
                      style="width:45%">
          <el-input v-model="infoForm.standard"
                    :disabled="isDisabled"></el-input>
        </el-form-item>
        <el-form-item label-width='170px' label="湿气敏感性等级（MSL）"
                      prop="level"
                      style="width:45%">
          <el-input v-model="infoForm.level"
                    :disabled="isDisabled"></el-input>
        </el-form-item>
        -->
        <el-form-item label-width='170px' label="数据列表"
                      prop="dataList"
                      style="width:45%">
          <el-input v-model="infoForm.dataList"
                    :disabled="isDisabled"></el-input>
        </el-form-item>

        <el-form-item label-width='170px' label="包装方式"
                      prop="pack"
                      style="width:45%">
          <el-input v-model="infoForm.pack"
                    :disabled="isDisabled"></el-input>
        </el-form-item>

        <el-form-item label-width='170px' label="零件状态"
                      prop="partStatus"
                      style="width:45%">
          <el-input v-model="infoForm.partStatus"
                    :disabled="isDisabled"></el-input>
        </el-form-item>

        <el-form-item label-width='170px' label="重量（g）"
                      prop="weight"
                      style="width:45%;">
          <el-input v-model="infoForm.weight"
                    :disabled='isDisabled'></el-input>
        </el-form-item>
        <!--
        <el-form-item label="lifeData" prop="lifeData" style="width:40%" >
            <el-input v-model="infoForm.lifeData"
                    style="width:100%"
                    :disabled="isDisabled"></el-input>
        </el-form-item>
        -->
        <el-form-item label-width='170px' label="环保信息" prop="rosh" style="width:45%" >
                <el-input v-model="infoForm.rosh"
                    :disabled="isDisabled"></el-input>
        </el-form-item>

        <el-form-item label-width='170px' label="主类别"
                      prop="cateName"
                      style="width:45%">
           <el-input v-model="infoForm.cateName"
                    :disabled="isDisabled"></el-input>
        </el-form-item>
        <el-form-item label-width='170px' label="子类别"
                      prop="catesonName"
                      style="width:45%">
          <el-input v-model="infoForm.catesonName"
                    style="width:100%"
                    :disabled="isDisabled"></el-input>
        </el-form-item>

        <el-form-item label-width='170px' label="规格描述"
                      prop="storeInfo"
                      style="width:45%">
              <el-input v-model="infoForm.storeInfo"
                    :disabled="isDisabled"></el-input>
        </el-form-item>
        <el-form-item label-width='170px' label="促销信息"
                      prop="content"
                      style="width:45%">
          <el-input v-model="infoForm.content"
                    type="textarea"
                    :autosize="{minRows: 2}"
                    style="width:100%"
                    :disabled="isDisabled"></el-input>
        </el-form-item>
         <el-form-item label-width='170px' label="成本价"
                      prop="costPrice"
                      style="width:45%">
          <el-input v-model="infoForm.costPrice"
                    :disabled="isDisabled"></el-input>
        </el-form-item>

        <el-form-item label-width='170px' label="进货价"
                      prop="stockPrice"
                      style="width:45%;">
          <el-input v-model="infoForm.stockPrice"
                    :disabled='isDisabled'></el-input>
        </el-form-item>

        <el-form-item label-width='170px' label="库存"
                      prop="stock"
                      style="width:45%;">
          <el-input v-model="infoForm.stock"
                    :disabled='isDisabled'></el-input>
        </el-form-item>
                <el-form-item label-width='170px' label="产品料号图片"
                      prop="image"
                      style="width:45%">
            <!-- 缩略图 -->
            <div v-if="infoForm.image">
              <el-image :src="infoForm.image"
                        fit="cover" style="width: 30%; height: 30%"></el-image>
            </div>
        </el-form-item>
      </el-form>

      <el-form ref="productForm"
               :model="productForm"
               class="infos flex">
        <el-form-item label="梯度1起始数量"
                      prop="description"
                      style="width:30%">
              <el-input v-model="infoForm.countstart1"
                    :disabled="isDisabled"></el-input>
        </el-form-item>
        <el-form-item label="梯度1结束数量"
                      prop="description"
                      style="width:30%">
              <el-input v-model="infoForm.countend1"
                    :disabled="isDisabled"></el-input>
        </el-form-item>

         <el-form-item label="梯度1价格"
                      prop="description"
                      style="width:30%">
              <el-input v-model="infoForm.price1"
                    :disabled="isDisabled"></el-input>
        </el-form-item>

        <el-form-item label="梯度2起始数量"
                      prop="description"
                      style="width:30%">
              <el-input v-model="infoForm.countstart2"
                    :disabled="isDisabled"></el-input>
        </el-form-item>
         <el-form-item label="梯度2结束数量"
                      prop="description"
                      style="width:30%">
              <el-input v-model="infoForm.countend2"
                    :disabled="isDisabled"></el-input>
        </el-form-item>

         <el-form-item label="梯度2价格"
                      prop="description"
                      style="width:30%">
              <el-input v-model="infoForm.price2"
                    :disabled="isDisabled"></el-input>
        </el-form-item>

        <el-form-item label="梯度3起始数量"
                      prop="description"
                      style="width:30%">
              <el-input v-model="infoForm.countstart3"
                    :disabled="isDisabled"></el-input>
        </el-form-item>
         <el-form-item label="梯度3结束数量"
                      prop="description"
                      style="width:30%">
              <el-input v-model="infoForm.countend3"
                    :disabled="isDisabled"></el-input>
        </el-form-item>

         <el-form-item label="梯度3价格"
                      prop="description"
                      style="width:30%">
              <el-input v-model="infoForm.price3"
                    :disabled="isDisabled"></el-input>
        </el-form-item>
         <el-form-item label="大于梯度3结束数量的价格"
                      prop="description"
                      style="width:45%">
              <el-input v-model="infoForm.price4"
                    :disabled="isDisabled"></el-input>
        </el-form-item>

         <el-form-item label="规格书下载"
                      prop="shopPdf"
                      style="width:45%">
            <el-link type="primary" :href="infoForm.shopPdf" target="_blank">{{infoForm.shopPdf}}</el-link>
        <el-form-item label="是否上架"
                      prop="producer"
                      style="width:50%;">
                     
                <el-switch
                  v-model="infoForm.isShow"
                  active-text="上架"
                  inactive-text="未上架" 
                  :active-value="1"
                  :inactive-value="0"
                  active-color="#13ce66"
                  inactive-color="#ff4949"
                  disabled
                  >
                </el-switch> 
 

        </el-form-item>
        
        </el-form-item>
        


       

      </el-form> 
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="dialogDetail = false">返回</el-button>
      </div>
    </el-dialog>
    <!-- 交货期 -->
		<el-dialog title="请选择交货期" :visible.sync="rolePopup" :close-on-click-modal="false" :close-on-press-escape="false" width="30%">
      
			<el-form :model="roleForm" label-position="left" label-width="80px" >
        <el-form-item prop="id" style="height:0">
					<el-input type="hidden" v-model="roleForm.id" clearable auto-complete="off" :disabled="true"></el-input>
			</el-form-item>
				<el-form-item label="交货期" prop="当天发货">
					<el-select v-model="roleForm.dateName" clearable style="width:100%">
						<el-option v-for="(dateDate,index) in roleList" :key="index" :label="dateDate.dateName" :value="dateDate.dateName">
						</el-option>
					</el-select>
				</el-form-item>
			</el-form>

			<span slot="footer" class="dialog-footer">
				<el-button @click="rolePopup = false">取 消</el-button>
				<el-button type="primary"
						@click="roleListClick">确 定</el-button>
      		</span>
		</el-dialog>
  </div>
</template>

<script>
import { export2Excel } from "@/utils/utils";
import axios from "axios";
import {
  PRODUCT_LIST,PRUDUCT_DETAIL,
  PRODUCT_ADD,UPDATE_PRODUCT_FILE,
  PRODUCT_UPDATE,
  PRODUCT_BATCHDELETE,
  SUPPLIER_ALLLIST,PRODUCT_UPPER_SHELF,
  PRODUCT_DOWNLOAD,PRODUCT_LOWER_SHELF,
  PRODUCT_IMAGE_FILE,PRODUCT_MODIFY_PRICE,
  PRODUCTAPPLY
} from "@/utils/api";
import { Message } from "element-ui";

export default {
  data() {
    return {
      swich_val:1,
      rolePopup:false,
      roleForm:{},
      roleList:[
          {dateName: "当天发货" },
          {dateName: "两天内发货" },
          {dateName: "三天内发货" },
          {dateName: "一周内发货" },
      ],
      isDisabled:true,
      dialogDetail:false,
      pdfUrl: "",
      uploadValue: "上架",
      uploadDialogVisible: false,
      uploadFoxDateSheetVisible:false,
      uploadShopDateSheetVisible:false,
      uploadDateSheetVisible: false,
      uploadExcelSheetVisible:false,
      priceTableData: [
        {
          date: "价格梯度1",
          startCount: "0",
          endCount: "10",
          price: "100"
        },
        {
          date: "价格梯度2",
          startCount: "10",
          endCount: "20",
          price: "95"
        },
        {
          date: "价格梯度3",
          startCount: "20",
          endCount: "30",
          price: "90"
        },
        {
          date: "价格梯度4",
          startCount: "30",
          endCount: "40",
          price: "87"
        },
        {
          date: "价格梯度5",
          startCount: "40",
          endCount: "50",
          price: "85"
        }
      ],
      columns: [
        { title: "id", key: "id" },
        { title: "aks料号", key: "aks" },
        { title: "制造商编号", key: "product_num" },
        { title: "制造商", key: "product_name" }
      ],
      dialogTableVisible: false,
      dialogDetailFormVisible: false,
      name: "",
      modify: 0,
      isDisabled: false,
      // 上传
      updateForm: { imageUrl: "", pdfUrl: "" ,excelUrl:""},
      file: null,
      loadings: "",
      hiddenFile: null,
      downLoadForm: {
        showValue:null,
        value:null,
        AllSlist: [
          { id: 1, menuName: "傲然" },
          { id: 2, menuName: "咩咩" },
          { id: 3, menuName: "mc" },
          { id: 4, menuName: "lulu" }
        ],
        productCode: "",
        isShow: false,
        cateId: [
          { id: 1, menuName: "傲然" },
          { id: 2, menuName: "咩咩" },
          { id: 3, menuName: "mc" },
          { id: 4, menuName: "lulu" }
        ],
        partXl: [
          { id: 1, menuName: "傲然" },
          { id: 2, menuName: "咩咩" },
          { id: 3, menuName: "mc" },
          { id: 4, menuName: "lulu" }
        ]
      },
      options1: [
        { id: 1, name: "供应商1" },
        { id: 2, name: "供应商2" },
        { id: 3, name: "供应商3" },
        { id: 4, name: "供应商4" }
      ],
      gridData: [
        {
          id: "1",
          aks: "7887544",
          product_num: "DSC20456-4K87JT4",
          product_name: "供应商x"
        },
        {
          id: "2",
          aks: "45ashj1",
          product_num: "DSC20456-asdaJT4",
          product_name: "供应商x"
        },
        {
          id: "3",
          aks: "1343sf1",
          product_num: "DSC20456-4dfffa1",
          product_name: "供应商x"
        },
        {
          id: "4",
          aks: "5081123",
          product_num: "DSC20456-asdas1s",
          product_name: "供应商x"
        },
        {
          id: "5",
          aks: "fdsf312",
          product_num: "DSC20456-4fffe1s",
          product_name: "供应商x"
        }
      ],
      showExport: false,
      searchForm: {
        showValue:null,
        value:null,
        orderNum: ""
      },
      formLabelWidth: "120px",
      dialogFormVisible: false,
      dialogProductFormVisible: false,
      productForm: {
        // liaohaoName:'',
        // price:'',
        // productNum:'',
        // stock:'',
        // isShow:1,
        //  attrName:'',
        //  attrVal:'',
      },
      infoForm: {
        // id:0,
        // cateId:'',
        // productCode:'',
        // storeName:'',
        // manufacturer:'',
        // standard:'',
        // level:'',
        // endData:'',
        // description:'',
        // dataList:'',
        // packStard:'',
        // pack:'',
        // partStatus:'',
        // partClass:'',
        // productZu:'',
        // partXl:'',
        // manufacturerCode,
        image: "",
        AllSlist: [
          { id: 1, menuName: "傲然" },
          { id: 2, menuName: "咩咩" },
          { id: 3, menuName: "mc" },
          { id: 4, menuName: "lulu" }
        ]
      },
      tableData: [
        // {
        //   id:0,
        //   image: "",
        //   manufacturerCode: "12312",
        //   manufacturer: "2335451",
        //   storeInfo: "BMW",
        //   pack: "sfds423g23g",
        //   specsBook: "10",
        //   stock: "吸塑",
        //   pricestocks: "xxx",
        //   productArea: "100",
        // }
      ],
      v:null,
      vData:null,
      currentPage: 1,
      pageSize: 10,
      total: 50,
      AllSlist: [],
      downloadUrl: "http://oss.dataos.top/",
      value: "",
      productCode:null,
      productId:null,
    };
  },
  mounted() {
    this.getAllList();
    this.getPoductList();
  },
  methods: {

      //上架申请
      uploadDialog(data) {
 
      this.vData=data
    
      this.v = data.isShow;
      //上架时判断是否配置梯度和交货期
          if(data.endData == "" && data.countstart1 == 0){
              Message({
              message: `请先配置价格梯度和交货期，再执行上架`,
              type: "error",
              duration: 2000
            });
          }else if(data.endData == ""){
              Message({
              message: `请先配置交货期，再执行上架`,
              type: "error",
              duration: 2000
            });
          }else if(data.countstart1 == 0){
              Message({
              message: `请先配置价格梯度，再执行上架`,
              type: "error",
              duration: 2000
            });
          }else{
              
            if(data.checkStatus == 1){
                  this.$message({
                    type: 'warning',
                    message: '您已申请该物料上架审批，请等待审批完成' 
                  });
                  return
            }

            this.$prompt('', '申请上架原因', {
                      confirmButtonText: '确定',
                      cancelButtonText: '取消',
                    }).then(({ value }) => {
                        
                    PRODUCTAPPLY({
                        id:data.id,
                        applyStatus:1,
                        applyInfo:value
                        }).then(res=>{
                          if(res.message == "SUCCESS" && res.status == 200){
                            data.checkStatus = 1;
                            this.$message({
                            type: 'success',
                            message: '申请成功' 
                          });
                          }
                        })
                      }).catch(() => {
                      this.$message({
                        type: 'info',
                        message: '取消申请'
                      });       
                    });


          }
           
      
      
    },
    //下架申请
    userapply(row){
         console.log("申请状态"+row.checkStatus)
   
        if(row.checkStatus == 1){
           this.$message({
            type: 'warning',
            message: '您已申请该物料下架审批，请等待审批完成' 
          });
          return
        }

        this.$prompt('', '申请下架原因', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
        }).then(({ value }) => {
             
        PRODUCTAPPLY({
            id:row.id,
            applyStatus:2,
            applyInfo:value
            }).then(res=>{
              if(res.message == "SUCCESS" && res.status == 200){
                row.checkStatus = 1;
                this.$message({
                type: 'success',
                message: '申请成功' 
              });
              }
         })


        }).catch(() => {
          this.$message({
            type: 'info',
            message: '取消申请'
          });       
        });

    },

    //交货期
    selectDate(row){
        this.rolePopup = true
        this.productId = row.id
        
    },
    roleListClick() {
        console.log(this.productId)
        if(!this.roleForm.dateName){
           this.$message.warning('请选择交货期')
        }
      
        PRODUCT_UPDATE({
          id:this.productId,
          endData:this.roleForm.dateName,
        }).then(res=>{
           this.rolePopup = false
          this.$message.success("交货期设置成功");
           this.getPoductList();
        })
		},
    showShopUpDialog(row){
      this.productId=row.id
      this.uploadShopDateSheetVisible=true
      
    },
    showFoxUpDialog(row){
      this.productId=row.id
      this.uploadFoxDateSheetVisible=true
    },
    uploadFoxSource(){
      UPDATE_PRODUCT_FILE({
        id:this.productId,
        filePath:this.pdfUrl,
        fileType:2
      }).then(res=>{
         this.uploadFoxDateSheetVisible=false
         this.updateForm.pdfUrl = "";
         this.$message.success("更新文档成功");
         this.getPoductList();
      })
    },
    uploadShopSource(){
      UPDATE_PRODUCT_FILE({
        id:this.productId,
        filePath:this.pdfUrl,
        fileType:1
      }).then(res=>{
        this.uploadShopDateSheetVisible=false
        this.updateForm.pdfUrl = "";
        this.$message.success("更新文档成功");
        this.getPoductList();
      })
    },
    updateShelf(){
      if(this.v==1){
        PRODUCT_LOWER_SHELF({
          id:this.vData.id
        }).then(res=>{
          if (res.status == 200) {
            this.$message.success("下架成功");
            this.uploadDialogVisible = false
            this.getPoductList()
          }
        })
      }else{
        PRODUCT_UPPER_SHELF({
          id:this.vData.id
        }).then(res=>{
          if (res.status == 200) {
            this.$message.success("上架成功");
            this.uploadDialogVisible = false
            this.getPoductList()
          }
        })
      }
    },
    updatePrice(row){
      this.productForm=row
      this.productCode=row.productCode
      this.dialogProductFormVisible=true
    },
    modifyPrice(){
      //判断数据不能为空 和 0 

      if (
        this.productForm.countstart1 == "" ||
        this.productForm.countstart1 == 0 ||
        this.productForm.countend1 == "" ||
        this.productForm.countend1 == 0 ||
        this.productForm.price1 == "" ||
        this.productForm.price1 == 0 ||
        this.productForm.countstart2 == "" ||
        this.productForm.countstart2 == 0 ||
        this.productForm.countend2 == "" ||
        this.productForm.countend2 == 0 ||
        this.productForm.price2 == "" ||
        this.productForm.price2 == 0 ||
        this.productForm.countstart3 == "" ||
        this.productForm.countstart3 == 0 ||
        this.productForm.countend3 == "" ||
        this.productForm.countend3 == 0 ||
        this.productForm.price3 == "" ||
        this.productForm.price3 == 0 ||
        this.productForm.price4 == "" ||
        this.productForm.price4 == 0 

      ) {
        Message({ message: "梯度信息必须合法", type: "error", duration: 2000 });
      }else{
        PRODUCT_MODIFY_PRICE({
                productCode:this.productCode,
                countstart1:this.productForm.countstart1,
                countend1:this.productForm.countend1,
                price1:this.productForm.price1,
                countstart2:this.productForm.countstart2,
                countend2:this.productForm.countend2,
                price2:this.productForm.price2,
                countstart3:this.productForm.countstart3,
                countend3:this.productForm.countend3,
                price3:this.productForm.price3,
                countstart4:parseInt(this.productForm.countend3)+1,
                price4:this.productForm.price4,
            }).then(res=>{
                if (res.status == 200) {
                  Message({
                    message: `梯价已更新`,
                    type: "success",
                    duration: 2000
                  });
                  this.dialogProductFormVisible = false
                  this.getPoductList();
                }
            })
      }

    },
    detail(row){
      PRUDUCT_DETAIL({
        id:row.id
      }).then(res => {
          if (res.status == 200) {
            this.dialogDetail=true
            this.isDisabled=true
            this.infoForm=res.data;
            if(row.shopPdf!=''){
              this.infoForm.shopPdf=this.downloadUrl+row.shopPdf
            }
           
          }
      });
      
    },
    searchData(){
      this.getPoductList();
    },
    downloadExcelModel(){
        var url = 'http://yzbban.oss-cn-shanghai.aliyuncs.com/excel/example/modify_price_example.xlsx'
        location.href = url
    },
    downloadFox(row){
      if(""==row.foxPdf){
        this.$message.error("文件不存在");
      }else{
        var url = this.downloadUrl + row.foxPdf
        location.href = url
      }
    },
    downloadAml(row){
      if(""==row.amlPdf){
        this.$message.error("文件不存在");
      }else{
        var url = this.downloadUrl + row.amlPdf
        location.href = url
      }
     
    },

     // 上传前-拦截上传格式pdf
    beforeUploadExcel(file) {
      console.log("==file==>" + file);
      this.updateForm.excelUrl = "";
      this.pdfFile = file;
    },
    uploadExcel() {
      let param = new FormData(); // 创建form对象
      param.append("file", this.pdfFile);
      let config = {
        headers: { "Content-Type": "multipart/form-data" }
      };
      axios
        .post("http://fox.foxcore.cn/api/v1/product/modifyPriceByExcel", param, config)
        .then(response => {
          if (response.data.status === 200) {
            this.pdfUrl = response.data.data;
            this.updateForm.excelUrl =
              "http://oss.dataos.top/" +
              response.data.data;
            this.$message.success("上传Excel文档成功");
            this.getPoductList();
          }
        });
    },
    // 上传前-拦截上传格式pdf
    beforeUploadPdf(file) {
      console.log("==file==>" + file);
	    const isLt2M = file.size / 1024 / 1024 < 10;
	    if (!isLt2M) {
	      this.$message.error('上传头像图片大小不能超过 10MB!');
	   		return isLt2M;
	    }else{
	      this.updateForm.pdfUrl = "";
	      this.pdfFile = file;
	    }
    },
    uploadPdf() {
      let param = new FormData(); // 创建form对象
      param.append("file", this.pdfFile);
      let config = {
        headers: { "Content-Type": "multipart/form-data" }
      };
      axios
        .post("http://fox.foxcore.cn/api/v1/file/pdf/product", param, config)
        .then(response => {
          if (response.data.status === 200) {
            this.pdfUrl = response.data.data;
            this.updateForm.pdfUrl =
              "http://oss.dataos.top/" +
              response.data.data;
            this.$message.success("上传文档成功");
          }
        });
    },
    //制造商
    getAllList() {
      SUPPLIER_ALLLIST().then(res => {
        this.AllSlist = res.data;
        console.log(this.AllSlist);
      });
    },
    export2excel() {
      export2Excel(this.columns, this.tableData);
    },
    exportSubmit() {
      this.showExport = !this.showExport;
      let that = this;
      // 这里请求数据
      PRODUCT_DOWNLOAD({
        menuName: this.value
      }).then(res => {
        console.log(res.data);
        var url = that.downloadUrl + res.data;
        location.href = url;
      });
      // this.dialogTableVisible=!this.dialogTableVisible
    },
    exportCancel() {
      this.showExport = !this.showExport;
    },
    exportInfo() {
      this.showExport = !this.showExport;
    },
    delInfo() {
      if (this.$refs.multipleTable.selection.length == 0) {
        Message({
          message: "请先勾选要修改的项目",
          type: "warning",
          duration: 2000
        });
      } else {
        var deleteList = this.$refs.multipleTable.selection;
        var idlist = [];
        for (let i in deleteList) {
          idlist.push(deleteList[i].id);
        }
        PRODUCT_BATCHDELETE({
          idlList: idlist
        }).then(res => {
          if (res.status == 200) {
            Message({
              message: `${idlist}号料号已删除`,
              type: "success",
              duration: 2000
            });
            this.getPoductList();
          }
        });
      }
    },
    addInfo() {
      this.$router.push({
        path: "addProduct"
      });
    },
    getPoductList() {
      PRODUCT_LIST({
        productCode:this.searchForm.orderNum,
        isShow:this.searchForm.showValue,
        menuName:this.searchForm.value,
        pageNo: this.currentPage,
        pageSize: this.pageSize
      }).then(res => {
        console.log(res);
        this.tableData = res.data.dataList;
        this.total = res.data.count;
      });
    },
    deleteInfo(row) {
      console.log("===>" + row);
    },
    checkDetail(row) {
      this.$router.push({
        path: "addProduct",
        query: {
          data: row,
          handler: "check",
          detail: "ok"
        }
      });
    },
    getDetail(row) {
      this.$router.push({
        path: "liaohao",
        query: {
          id: row.id
        }
      });
    },
    modifyInfo(row) {
      this.$router.push({
        path: "addProduct",
        query: {
          data: row,
          handler: "edit",
          detail: "not"
        }
      });
    },
    handleSelectionChange(val) {
      console.log(val, "handleSelectionChange");
      this.multipleSelection = val;
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.getPoductList();
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.getPoductList();
    }
  }
};
</script>

<style lang="scss" scoped>
p {
  font-size: 20px;
  padding: 10px 0;
}

.infos {
  width: 100%;
  justify-content: space-between;
  flex-wrap: wrap;
  .item {
    width: 30%;
  }
}
.tableBox {
  width: 100%;
  background: #fff;
  padding: 10px 2px;
  border-radius: 5px;
  //   box-shadow: 2px 3px 15px 0 #ccc;
}
.alerts {
  z-index: 2001;
  position: fixed;
  top: 20%;
  bottom: 0;
  left: 0;
  right: 0;
  text-align: center;
}
.alertDiv {
  display: inline-block;
  width: 900px;
  vertical-align: middle;
  background-color: #fff;
  border-radius: 4px;
  border: 1px solid #ebeef5;
  font-size: 16px;
  -webkit-box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  text-align: left;
  overflow: hidden;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}
.alertDd {
  width: 80%;
  margin: 6% auto;
  color: #606266;
}
.buttomF {
  margin-right: 31%;
  margin-top: 1%;
  padding-bottom: 2%;
  float: right;
}
.alertBg {
  z-index: 2000;
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  opacity: 0.5;
  background: #000;
}

.searchAreaTop {
  width: 100%;
  justify-content: flex-start;
}
.searchArea {
  width: 100%;
  margin-top: 15px;
  justify-content: flex-start;
}

.dialog-footer {
  text-align: center;
}
</style>